function MachinesController($scope,$state,Notification,FileUploader,$http,MachineService,context,ErrorUtils){
	
	$scope.companyUuid = context.getEmployee().company.uuid;
	
	
	$scope.applications = [
	                       	{name:'Select Application Purpose',value:0},
	                       	{name:'Buffing & Polishing',value:1},
	                   		{name:'Carpet Extractor',value:2},
	                   		{name:'Scrubbing',value:3},
	                   		{name:'Scrubbing & Shampooing',value:4},
	                   		{name:'Steam Generator',value:5},
	                   		{name:'Sweeper cum Scrubber',value:6},
	                   		{name:'Sweeping',value:7},
	                   		{name:'Vacuuming',value:8},
	                   		{name:'Other',value:9}
	                       ];
	
	//Default Selection
	$scope.application = $scope.applications[0];
	
	$scope.machineTypes = [
	                       	{name:'Select Machine Type',value:-1},
							{name:'Carpet Extracter',value:0}, 
							{name:'Cold Water',value:1},
							{name:'Dry',value:2},
							{name:'Hot Water',value:3},
							{name:'Ride In',value:4},
							{name:'Ride On',value:5},
							{name:'Single Disk',value:6},
							{name:'Steam Generator',value:7},
							{name:'Walk Behid',value:8},
							{name:'Wet and Dry',value:9},
							{name:'Other',value:10},
	                       ];
	//Default Selection
	$scope.machineType = $scope.machineTypes[0]
	
	
	$scope.fuelTypes = [
	                    {name:'Select Fuel Type',value:0},
	                    {name:'Battery',value:1},
	                    {name:'Diesal',value:2},
	                    {name:'Electric',value:3},
	                    {name:'LPG',value:4},
	                    {name:'Manual Petrol',value:5},
	                    {name:'Other',value:6}
	                    
	                    ];
	
	//Default Selection
	$scope.fuelType = $scope.fuelTypes[0];
	
	$scope.machinesList = [];
	
	
	$scope.submitMachine = function(){
		
		var data = 	"application="+$scope.application.name+"&" +
					"machineType="+$scope.machineType.name+"&" +
					"brand="+$scope.brand+"&" +
					"model="+$scope.model+"&" +
					"origin="+$scope.origin+"&" +
					"fuelType="+$scope.fuelType.name+"&" +
					"runTime="+$scope.runTime+"&" +
					"areaCoverage="+$scope.areaCoverage+"&" +
					"capacity="+$scope.capacity+"&"+
					"companyUuid="+$scope.companyUuid;
		
		var save = MachineService.save(data);
		
		save.$promise.then(
				function(data){
					if(data.meta.code == 200){
						console.log("Data:",data);
						Notification.success({message: 'Record saved successfully.', title: 'Success'});
						for(index in data.data){
							$scope.machinesList.push(data.data[index]);
						}
					}
					else{
						Notification.error({message:ErrorUtils.getMessageByErrorCode(data.meta.code), title: 'Error'});
					}
					
				},
				function(error){					
					Notification.error({message: "Some error occurred. Please try again later.", title: 'Error'});
				});
	};
	
	$scope.getMachinesList = function(){
		$scope.machinesList = [];
		var get = MachineService.get({id:$scope.companyUuid});
		
		get.$promise.then(
				function(data){
					if(data.meta.code == 200){
						console.log("Data:",data);
						for(index in data.data){
							$scope.machinesList.push(data.data[index]);
						}
					}
					else{
						Notification.error({message:ErrorUtils.getMessageByErrorCode(data.meta.code), title: 'Error'});
					}
					
				},
				function(error){
					Notification.error({message: "Some error occurred. Please try again later.", title: 'Error'});
				});
	}
	
	$scope.deleteMachine = function(uuid,index){
		var del = MachineService.delete({id:uuid});
		
		del.$promise.then(
				function(data){
					if(data.meta.code == 200){
						console.log("Data:",data);
						$scope.deleteItemFromMachinesList(index);
					}
					else{
						Notification.error({message:ErrorUtils.getMessageByErrorCode(data.meta.code), title: 'Error'});
					}
					
				},
				function(error){
					Notification.error({message: "Some error occurred. Please try again later.", title: 'Error'});
				});
	}
	
	$scope.deleteItemFromMachinesList = function(index){
		var from 	= index;
		var to		= 0;
		var rest = $scope.machinesList.slice((to || from) + 1 || $scope.machinesList.length);
		$scope.machinesList.length = from < 0 ? $scope.machinesList.length + from : from;
		$scope.machinesList.push.apply($scope.machinesList, rest);
	}
	
	
	
	$scope.getMachinesList();
	

}


angular.module('supplier.machines',['ngAnimate','ui.router','ui-notification','angularFileUpload','ng.httpLoader'])
	.controller('MachinesController',['$scope','$state','Notification','FileUploader','$http','MachineService','context','ErrorUtils',MachinesController])
	